1. Field of the Invention
The invention relates to representation, storage and manipulation of timestamps. More particularly, it relates to new methods, apparatus and data structures for transforming date/time information into an efficiently stored and easily manipulated data structure for use in computer systems.
2. Description of the Related Art
Conventional methods for the representation and storage of date/time information are highly inefficient.
For example, the INFORMIX(copyright) database uses a 24-byte timestamp structure for representing date/time information. These timestamps take the form of YYYY-MM-DD HH-mm-SS.FFFFF where YYYY is the year, MM the month, DD the Day, HH the hour, mm the minute, SS the second, and FFFFF the number of 10""s of microseconds. Although such a representation includes metadata information that allows it to store many kinds of date/time information, including such information makes the timestamp much larger than necessary to represent many simpler date/time information formats. The resulting 24-byte structure is, therefore, time consuming to construct from date/time information, makes inefficient use of available memory and cannot be efficiently evaluated in boolean comparison operations.
For example, a 24-byte timestamp structure is ill-suited for use with in-memory timestamped data, such as time series data. In such an operation scenario, the number of records that can be stored in memory is directly related to the size of the records. A smaller record size allows a larger number of records to be fit in a fixed amount of memory space. By increasing the number of records that fit in memory, the number of disk I/O operations required to support page in/out record operations is reduced.
By way of an operational example, if an in-memory database were used to track the trading price of a publicly traded stock, a typical record would include a timestamp and a single floating point number that is used to record the value of the stock at the time indicated by the timestamp. In such a case, each record would require 24-bytes of storage for the timestamp and 8-bytes for the floating point number, making the overhead for the timestamp three times that of the information that the application is designed to track. Therefore, in 1024-bytes of memory there could be at most 32 of the 32-byte records. If the size of a timestamp is reduced to 8-bytes, the number of records that could be stored in 1024-bytes of memory would increase to 64, thus doubling the number of records that could be stored in the same amount of memory.
Conventional methods for creating, representing and storing date/time information require significant processor resources. For example, with respect to the 24-byte INFORMIX(copyright) timestamp, not only is the timestamp encoded into a binary string, additional metadata bytes are set to indicate such variables as: the granularity of the date/time information; the number of bytes actually present in the date string; a positive/negative/null indicator; and, a count of the number of fields in the structure prior to the microseconds information. In total, five fields must be set when constructing an INFORMIX(copyright) timestamp. Furthermore, in executing a boolean comparison of two such timestamps, all these fields must be checked. As a result, performance of boolean timestamp comparisons, using conventional timestamp techniques, are very inefficient.
Other conventional techniques for efficiently representing date/time information suffer from other, yet equally strong deficiencies. For example, conventional methods for converting timestamps into 8-byte representations are slow to create. These solutions typically involve picking some epoch in time, such as Jan. 1, 1970, and then calculating the number of seconds and microseconds between a given timestamp and the epoch. Such an approach is complicated and inefficient, since the conversion of date/time information to such a format must handle leap years, leap seconds and leap microseconds. Such approaches typically include a time zone, associated with converted time stamps, that must be accounted for when processing such timestamps. Because of this complexity, it is time consuming to convert date/time information to one of these conventional 8-byte timestamp formats.
There remains a strong need for more efficient methods, apparatus and data structures for storing and manipulating date/time information.
Therefore, in light of the above, and for other reasons that will become apparent when the invention is fully described, methods, apparatus and data structures for representing, storing and manipulating timestamps are described here.
Methods, apparatus and data structures are described for representing, storing and manipulating date/time information in an 8-byte timestamp format. By limiting date/time information to a range between 0001-01-01 00:00:00.00000 and 18446-12-31 23:59:59:99999 and specifying a single date/time granularity, an 8-byte timestamp is generated that is capable of conveying the same operational information as conventional 24-byte timestamps, yet which can be more efficiently generated, more efficiently stored, and more efficiently evaluated using boolean operations.
The above features and advantages of the invention will become apparent upon consideration of the following descriptions and descriptive figures of specific embodiments thereof. While these descriptions go into specific details of the invention, it should be understood that variations may and do exist and would be apparent to those skilled in the art based on the descriptions herein.